<template>
  <div>
    <el-form ref="form" class="input" :model="permission" label-width="80px">
      <el-form-item label="权限名称">
        <el-input  v-model="permission.permissionName"></el-input>
      </el-form-item>
      <el-form-item label="权限路由">
        <el-input v-model="permission.url"></el-input>
      </el-form-item>
       <el-form-item>
          <el-button type="primary" @click="updatePermission">修改</el-button>
          <router-link :to="'/permission/list'">
          <el-button >取消</el-button>
          </router-link>
        </el-form-item>
      </el-form>
  </div>
</template>

<script>
  import permission from'@/api/permission/permission'
  export default {
    data() {
      return {
       permission:{
         id:-1,
         permissionName:'',
         url:''
       },
    }
    },
    created() {
       if(this.$route.params && this.$route.params.id){
           this.permission.id=this.$route.params.id
           this.getPermissionById()
       }
    },
    methods: {
     // updateAdmin(){
     //   adminApi.updateAdmin(this.admin)
     //   .then(response=>{
     //     this.$message({
     //       type: 'success',
     //       message: '修改成功!'
     //     });
     //     this.$router.push({ path: '/admin/table' })
     //   })
     //   }
     // ,
     getPermissionById(){
       permission.getPermissionById(this.permission.id)
       .then(response=>{
         this.permission=response.data.permission
       })
     },
     updatePermission(){
       permission.updatePermission(this.permission)
       .then(response=>{
         this.$message({
           type: 'success',
           message: '修改成功!'
         });
         this.$router.push({ path: '/permission/list' })
       })
     }
    }
  }
</script>

<style>
</style>
